package com.ljs.tranctionldemo.util;

import lombok.Data;
import lombok.ToString;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * @Description:
 * @Author: liujinsheng
 * @Date: 2021/6/28.
 */
@Data
@ToString
public class BasePageResult<T> implements Serializable {
    /**
     * 每页显示条数
     */
    private Long size;

    /**
     * 当前页
     */
    private Long page;

    /**
     * 总数
     */
    private Long total;

    /**
     * 总页数
     */
    private Long totalPage;

    public BasePageResult() {
    }

    public BasePageResult(Long page, Long size, Long total, List<T> records) {
        this.page = page;
        this.size = size;
        this.total = total;
        this.records = records;
    }

    /**
     * 是否存在下一页
     *
     * @return true / false
     */
    public boolean hasNext() {
        return this.page < this.totalPage;
    }

    public Long getTotalPage() {
        this.totalPage = total / size;
        if (total % size > 0) {
            this.totalPage++;
        }
        return this.totalPage;
    }

    /**
     * 查询数据列表
     */
    protected List<T> records = Collections.emptyList();
}
